package com.example.prom.dangwen.y2023.thread;

import lombok.SneakyThrows;

import java.util.concurrent.Semaphore;

public class printThead02 {

    private static Semaphore a = new Semaphore(1);
    private static Semaphore b = new Semaphore(0);
    private static Semaphore c = new Semaphore(0);

    static class A implements Runnable{
        @SneakyThrows
        @Override
        public void run() {
            a.acquire();
            System.out.println("A");
            b.release();
        }
    }

    static class B implements Runnable{

        @SneakyThrows
        @Override
        public void run() {
            b.acquire();
            System.out.println("B");
            c.release();
        }
    }

    static class C implements Runnable{

        @SneakyThrows
        @Override
        public void run() {
            c.acquire();
            System.out.println("C");
            a.release();
        }
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread t1 = new Thread(new A());
            Thread t2 = new Thread(new B());
            Thread t3 = new Thread(new C());
            t1.start();
            t2.start();
            t3.start();
        }

    }
}
